package letsjava.pattern.chainofresponse;

public class ConcreteHandler implements Handler {
	private Handler successor;

	public ConcreteHandler(Handler successor) {
		this.successor = successor;
	}

	public void handleRequest(Request request) {
		if (request instanceof HelpRequest) {
			System.out.println("request processed by ConcreteHandler");
			request.execute();
		} else {
			// 传递到下一个
			successor.handleRequest(request);
		}
	}
	
	public static void main(String[] args){
		ConcreteHandler2 handler2 = new ConcreteHandler2(null);
		ConcreteHandler handler = new ConcreteHandler(handler2);
		HelpRequest a = new HelpRequest("help");
		PrintRequst b = new PrintRequst("print");
		
		handler.handleRequest(a);
		handler.handleRequest(b);
		
	}
}